package com.ruoyi.product.controller;

import java.util.List;
import java.io.IOException;
import java.util.UUID;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.product.domain.Mycomment;
import com.ruoyi.product.service.IMycommentService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 商品评论Controller
 *
 * @author 林道敬
 * @date 2025-01-03
 */
@RestController
@RequestMapping("/comment")
public class MycommentController extends BaseController
{
    @Autowired
    private IMycommentService mycommentService;


    /**
     * 查询商品评论列表
     */
   // @RequiresPermissions("product:comment:list")
    @GetMapping("/list")
    public TableDataInfo list(Mycomment mycomment)
    {

        startPage();
        List<Mycomment> list = mycommentService.selectMycommentList(mycomment);
        return getDataTable(list);
    }

    /**
     * 导出商品评论列表
     */
    @RequiresPermissions("product:comment:export")
    @Log(title = "商品评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Mycomment mycomment)
    {
        List<Mycomment> list = mycommentService.selectMycommentList(mycomment);
        ExcelUtil<Mycomment> util = new ExcelUtil<Mycomment>(Mycomment.class);
        util.exportExcel(response, list, "商品评论数据");
    }

    /**
     * 获取商品评论详细信息
     */
    @RequiresPermissions("product:comment:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mycommentService.selectMycommentById(id));
    }

    /**
     * 新增商品评论
     */
    @RequiresPermissions("product:comment:add")
    @Log(title = "商品评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Mycomment mycomment)
    {

        return toAjax(mycommentService.insertMycomment(mycomment));
    }

    /**
     * 修改商品评论
     */
    @RequiresPermissions("product:comment:edit")
    @Log(title = "商品评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Mycomment mycomment)
    {
        return toAjax(mycommentService.updateMycomment(mycomment));
    }

    /**
     * 删除商品评论
     */
    @RequiresPermissions("product:comment:remove")
    @Log(title = "商品评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mycommentService.deleteMycommentByIds(ids));
    }
}
